home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / stat_ac.exe / STATUS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-01-22  |  5.1 KB  |  149 lines

  1. unit Status;
  2.  
  3. { This unit implements a modeless status box in a BorDlg-class dialog. The
  4.   dialog displays three lines of text which may be changed using the dialogs
  5.   Update method. The dialog maintains a boolean field called Continue which is
  6.   set to true in the constructor and becomes false when the user cancels the
  7.   dialog. See the comments below for more details.Complete source, including the
  8.   resource scripts is provided.
  9.  
  10.   To see a TStatusDlg object in action, build and run TEST.PAS included in this
  11.   zipfile.
  12.  
  13.   Contributed by Adam Carney 71150,2436 }
  14.  
  15.  
  16.  
  17. {$R STATUS.RES}
  18.  
  19. interface
  20.  
  21. uses WinTypes, WinProcs, OWindows, ODialogs, Strings;
  22.  
  23. const {$I CONST.PAS}
  24.  
  25. type
  26.  
  27. {INTERFACE ********* TStatusMsg *********************************************}
  28.   PStatusDlg = ^TStatusDlg;
  29.   TStatusDlg = object(TDialog)
  30.     Continue:boolean;
  31.     Title, Message, CancelMsg :PChar;
  32.     constructor Init(AParent:PWindowsObject; ATitle, AMessage, ACancelMsg:PChar);
  33.     procedure SetUpWindow; virtual;
  34.     procedure Update(ItemID:word; Src:PChar);
  35.     procedure ShowItem(ItemID:word; ACmd:integer);
  36.     procedure HandleEvents;
  37.     procedure ChangeButton;
  38.     procedure Complete(CompleteMsg:PChar);
  39.     procedure Cancel(var Msg:TMessage);
  40.       virtual id_First + id_Cancel;
  41.     destructor Done; virtual;
  42.   end;
  43.  
  44. implementation
  45.   constructor TStatusDlg.Init(AParent:PWindowsObject; ATitle, AMessage, ACancelMsg:PChar);
  46.   { Creates a new dialog object by calling the inherited constructor, sets the
  47.     Continue flag to true and stores three strings on the heap. Title will be used
  48.     to set the dialog caption; Message will be displayed in the first line of the
  49.     dialog; CancelMsg will be displayed in the first line when the box is cancelled }
  50.   begin
  51.     inherited Init(AParent,PChar(StatusDlgRes));
  52.     Continue:=true;
  53.     Title:=    StrNew(ATitle);
  54.     Message:=  StrNew(AMessage);
  55.     CancelMsg:=StrNew(ACancelMsg);
  56.   end;
  57.  
  58.   procedure TStatusDlg.SetUpWindow;
  59.   { In addition to the inherited SetUpWindow, sets the dialog caption to Title and
  60.     the first line to Message }
  61.   begin
  62.     inherited SetUpWindow;
  63.     SendMessage(HWindow,wm_SetText,0,Longint(Title));
  64.     Update(id_Stat1,Message);
  65.   end;
  66.  
  67.   procedure TStatusDlg.HandleEvents;
  68.   { Allows message processing while the host procedure is running. Called by Update,
  69.     HandleEvents is required in order to allow the user to click the Cancel button
  70.     or otherwise terminate the host process by typing escape or by choosing close
  71.     from the dialog's system menu }
  72.   var
  73.     Msg:TMsg;
  74.   begin
  75.     while PeekMessage(Msg,0,0,0,pm_Remove) do
  76.       if not IsDialogMessage(HWindow,Msg) then
  77.         begin
  78.           TranslateMessage(Msg);
  79.           DispatchMessage(Msg);
  80.         end;
  81.   end;
  82.  
  83.   procedure TStatusDlg.Update(ItemID:word; Src:PChar);
  84.   { Changes the text of the item with id of ItemID to that addressed by Src.
  85.     ItemID should be one of the constants id_Stat1, id_Stat2 or id_Stat3 to
  86.     change the displayed text of the first, second or third lines, respectively.
  87.     Calls HandleEvents to process all messages posted in the application queue
  88.     since the last call to Update }
  89.   begin
  90.     SendMessage(GetDlgItem(HWindow,ItemID),wm_SetText,0,LongInt(Src));
  91.     HandleEvents;
  92.   end;
  93.  
  94.   procedure TStatusDlg.ShowItem(ItemID:word; ACmd:integer);
  95.   { Sets the visible state of an Item. ShowItem is used to hide/display the OK and
  96.     Cancel buttons (which overlie each other) and lines of text in the dialog }
  97.   begin
  98.     ShowWindow(GetDlgItem(HWindow,ItemID),ACmd);
  99.   end;
  100.  
  101.   procedure TStatusDlg.ChangeButton;
  102.   { Hides the Cancel button and Shows the OK button. Has the appearance
  103.     of changing the Cancel button to an OK button }
  104.   begin
  105.     ShowItem(id_Cancel,sw_Hide);
  106.     ShowItem(id_OK,sw_Show);
  107.   end;
  108.  
  109.   procedure TStatusDlg.Cancel(var Msg:TMessage);
  110.   { Sets Continue to false, Sets first line to CancelMsg, hides 2nd and 3rd lines
  111.     of text and changes buttons.
  112.     Note: If continue is already false (not first time Cancel has been called) then
  113.     the inherited method is called to close the dialog box. This is reqired so that
  114.     the user can close the terminated status box using the escape key or the dialog's
  115.     system menu. }
  116.   begin
  117.     if Continue then
  118.       begin
  119.         Continue:=false;
  120.         Update(id_Stat1,CancelMsg);
  121.         ShowItem(id_Stat2,sw_Hide);
  122.         ShowItem(id_Stat3,sw_Hide);
  123.         ChangeButton;
  124.       end
  125.     else
  126.       inherited Cancel(Msg);
  127.   end;
  128.  
  129.   procedure TStatusDlg.Complete(CompleteMsg:PChar);
  130.   { Call update when the host procedure is finished. It changes the first line to
  131.     CompleteMsg, hides lines 2 and 3 and changes the Cancel button to OK }
  132.   begin
  133.     Update(id_Stat1,CompleteMsg);
  134.     ShowItem(id_Stat2,sw_Hide);
  135.     ShowItem(id_Stat3,sw_Hide);
  136.     ChangeButton;
  137.   end;
  138.  
  139.   destructor TStatusDlg.Done;
  140.   { Disposes of the Title, Messge and CancelMsg strings before calling the inherited
  141.     destructor }
  142.   begin
  143.     StrDispose(Title);
  144.     StrDispose(Message);
  145.     StrDispose(CancelMsg);
  146.     inherited Done;
  147.   end;
  148.  
  149. end.